package com.GUI.Lesson04;
//弹窗
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

//主窗口
public class DialogDemo extends JFrame {
    public DialogDemo(){
        setVisible(true);
        setBackground(Color.CYAN);
        setBounds(20,20,700,500);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //JFrame 放东西 容器
        Container container = this.getContentPane();
        //绝对布局
        container.setLayout(null);
        //按钮
        JButton button = new JButton("点击弹出对话框");
        //绝对定位下的按钮位置写法
        button.setBounds(30,30,200,50);
        //点击这个button时要弹出新的窗口
        button.addActionListener(new AbstractAction() {
            //监听器
            @Override
            public void actionPerformed(ActionEvent e) {
                //调用新的弹窗
                new MyDialogDemo();
            }
        });
        container.add(button);
    }

    public static void main(String[] args) {
        new DialogDemo();

    }

}
//弹窗的窗口
class MyDialogDemo extends  JDialog{
    public MyDialogDemo(){
        this.setVisible(true);
        this.setBounds(100,100,500,500);

        Container container = this.getContentPane();//生成面板
        container.setLayout(null);//设置为空
        container.setLayout(new FlowLayout(FlowLayout.CENTER));//设置布局

        container.add(new Label("hi"));
    }

}